package com.ajocer.springbootinit.config;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * 指标监控配置类
 */
@Configuration
public class MetricsConfig {

    /**
     * 自定义MeterRegistry配置
     */
    @Bean
    public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags(Environment environment) {
        return registry -> {
            // 添加通用标签
            registry.config()
                    .commonTags("application", "tourism-backend")
                    .commonTags("env", environment.getActiveProfiles().length > 0 ? 
                            environment.getActiveProfiles()[0] : "default");
        };
    }

    /**
     * 如果没有其他MeterRegistry实现，提供一个简单实现
     * 通常Spring Boot Actuator会自动配置一个
     */
    @Bean
    public SimpleMeterRegistry simpleMeterRegistry() {
        return new SimpleMeterRegistry();
    }
} 